# Function to create matrix based on parameters
create_rank_matrix <- function(attribute1=NULL, attribute2=NULL, priority=NULL){
  # abortion: L=pro-life, C=pro-choice
  att1 <- c("L", "C")
  # taxation: I=increase taxes, D=decrease taxes
  att2 <- c("D", "I")
  # create 2x2 comparisons
  comp1 <- as.character(paste(att1[1], att2[1], sep=""))
  comp2 <- as.character(paste(att1[1], att2[2], sep=""))
  comp3 <- as.character(paste(att1[2], att2[1], sep=""))
  comp4 <- as.character(paste(att1[2], att2[2], sep=""))
  # 1) homogeneous preferences for both attributes and identical prioritization
  if(attribute1=="homogeneous" & attribute2=="homogeneous" & priority=="identical"){
    # abortion: both prefer pro-life to pro-choice (L > C)
    # tax: both prefer decrease to increase (D > I)
    # both types of voters prioritize candidates along abortion dimension (i.e. only vote for candidates that are pro-life) 
    ranks_mat <- list("1" = c(1:4),
                      "2" = c(1:4),
                      "1a" = c(1:2, rep(NA, 2)),
                      "2a" =c(1:2, rep(NA, 2)))
  }
  # 2) homogeneous preferences for both attributes and disparate prioritization 
  # (i.e., voter type 1 care most about abortion policy but voter type 2 cares most about tax policy)
  if(attribute1=="homogeneous" & attribute2=="homogeneous" & priority=="disparate"){
    # abortion: both prefer pro-life to pro-choice (L > C)
    # tax: both prefer decrease to increase (D > I)
    # V1 prioritize candidates along abortion dimension (i.e. only vote for candidates that are pro-life) 
    # V2 prioritize candidates along tax dimension (i.e. only vote for candidates that are D) 
    ranks_mat <- list("1" = c(1:4),
                      "2" = c(1, 3, 2, 4),
                      "1a" = c(1:2, rep(NA, 2)),
                      "2a" = c(1, NA, 2, NA))
  }
  # 3) heterogeneous preferences for both attributes and identical prioritization
  if(attribute1=="heterogenous" & attribute2=="heterogenous" & priority=="identical"){
    # V1: prefers pro-life to pro-choice (L > C) and decrease to increase (D > I)
    # V2: prefers pro-choice to pro-life (C > L) and increase to decrease (I > D)
    # both types of voters prioritize candidates along abortion dimension (i.e. only vote for candidates that are pro-life or pro-choice) 
    ranks_mat <- list("1" = c(1:4),
                      "2" = c(rev(1:4)),
                      "1a" = c(1:2, rep(NA, 2)),
                      "2a" = c(rep(NA, 2), 2, 1))
  }
  # 4) heterogeneous preferences for both attributes and disparate prioritization
  # V1: prefers pro-life to pro-choice (L > C) and decrease to increase (D > I)
  # and prioritizes along abortion dimension (i.e. only vote for candidates that are pro-life) 
  # V2: prefers pro-choice to pro-life (C > L) and increase to decrease (I > D)
  # and prioritizes candidates along tax dimension (i.e. only vote for candidates that are I) 
  if(attribute1=="heterogenous" & attribute2=="heterogenous" & priority=="disparate"){
    ranks_mat <- list("1" = c(1:4),
                      "2" = c(rev(1:4)), 
                      "1a" = c(1:2, rep(NA, 2)),
                      "2a" = c(NA, 2, NA, 1))
  }
  # 5) homogeneous preferences on the most preferred attribute and
  # heterogeneous preferences on the secondary attribute 
  # with identical prioritization
  # V1: prefers pro-life to pro-choice (L > C) and decrease to increase (D > I)
  # V2: prefers pro-life to pro-choice (L > C) and increase to decrease (I > D)
  # both types of voters prioritize candidates along abortion dimension (i.e. only vote for candidates that are pro-life) 
  if(attribute1=="homogeneous" & attribute2=="heterogenous" & priority=="identical"){
    ranks_mat <- list("1" = c(1:4),
                      "2" = c(2, 1, 4, 3),
                      "1a" = c(1:2, rep(NA, 2)),
                      "2a" = c(2, 1, rep(NA, 2)))
  }
  # 6) heterogeneous preferences on the most preferred attribute and 
  # homogeneous preferences on the secondary attribute 
  # with identical prioritization
  # V1: prefers pro-life to pro-choice (L > C) and decrease to increase (D > I)
  # V2: prefers pro-choice to pro-life (C > L) and decrease to increase (D > I)
  # both types of voters prioritize candidates along abortion dimension (i.e. only vote for candidates that are pro-life or pro-choice) 
  if(attribute1=="heterogenous" & attribute2=="homogeneous" & priority=="identical"){
    ranks_mat <- list("1" = c(1:4),
                      "2" = c(3, 4, 1, 2),
                      "1a" = c(1:2, rep(NA, 2)),
                      "2a" = c(rep(NA, 2), 1, 2))
    
  }
  # re-name columns to associated matchups
  for(i in 1:4){
    names(ranks_mat[[i]]) <- c(comp1, comp2, comp3, comp4)
  }
 # browser()
  return(ranks_mat)
}
